package org.example.test;

import org.example.utils.JDBCUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class Tags {
    //获取到表的列名
    public static void main(String[] args) throws SQLException {

        Connection connection = JDBCUtils.getConnection();
        String sql = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'tags'";

        PreparedStatement ps = null;
        ResultSet rs=null;
        try {
            ps = connection.prepareStatement(sql);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        try {
            rs=ps.executeQuery(sql);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        List<String> ls=new ArrayList<>();

        while(rs.next()){
           ls.add(rs.getString("COLUMN_NAME"));
        }
        System.out.println(ls.get(0));
        System.out.println(ls.size());
        System.out.println(ls);

//        List<Integer> tags = new TagsDao().tags(19);
//        System.out.println(tags);

//        try {
//            new ViewArticleDao().listPublish();
//        } catch (Exception e) {
//            throw new RuntimeException(e);
//        }
    }
}
